//=============================================================================
// SentinelCloak - Makes the Sentinel invisible whilst not firing.
//=============================================================================
class SentinelCloak extends SentinelUpgrade;

var Material InvisMaterial;
var bool bInvisible;

replication
{
	reliable if(Role == ROLE_Authority)
		bInvisible;
}

function InitFor(Sentinel S)
{
	Super.InitFor(S);
	bInvisible = true;
	Invisible();
}

//Become visible again when firing.
function Fired()
{
	Super.Fired();
	bInvisible = false;
	Visible();
	SetTimer(1.0, false);
}

function Timer()
{
	bInvisible = true;
	Invisible();
}

//Make sure new weapons are invisible too.
function ChangedWeapon()
{
	Super.ChangedWeapon();
	bInvisible = true;
	Invisible();
}

simulated function Invisible()
{
	if(Sentinel == None)
		return;

	Sentinel.SetOverlayMaterial(InvisMaterial, 86400.0, true);
	Sentinel.Visibility = 1;

	if(Sentinel.SWeapon != None && Sentinel.SWeapon.WeaponAttachment != None)
		Sentinel.SWeapon.WeaponAttachment.SetOverlayMaterial(InvisMaterial, 86400.0, true);

	if(Sentinel.TeamMarker != None)
		Sentinel.TeamMarker.bHidden = true;
}

simulated function Visible()
{
    if(Sentinel == None)
		return;

	Sentinel.SetOverlayMaterial(None, 0.0, true);
	Sentinel.Visibility = Sentinel.Default.Visibility;

	if(Sentinel.SWeapon != None && Sentinel.SWeapon.WeaponAttachment != None)
		Sentinel.SWeapon.WeaponAttachment.SetOverlayMaterial(None, 0.0, true);

	if(Sentinel.TeamMarker != None)
		Sentinel.TeamMarker.bHidden = false;
}

simulated event PostNetReceive()
{
	if(bInvisible)
		Invisible();
	else
		Visible();
}

simulated function Destroyed()
{
	bInvisible = false;
	Visible();
	Super.Destroyed();
}

defaultproperties
{
     InvisMaterial=FinalBlend'XEffectMat.Combos.InvisOverlayFB'
     AmmoCost=1
     UpgradeName="Cloaking Device"
     Description="Designed for those who prefer cunning over raw power, the cloaking device consists of an intricate network of optic fibres, lenses and mirrors designed to route light from one side of the Sentinel to the other giving the appearance that it is not there at all.|| Because it interferes with the active scanning required for accurate targeting, the cloaking device is automatically disabled when the Sentinel needs to fire."
     ActivateSound=Sound'TFMedia.Invisible'
     bNetNotify=True
}
